// components/prtSc/prtSc.js
let app = getApp()
import {storeBindingsBehavior} from 'mobx-miniprogram-bindings'
import store from '../../store/store'
import Notify from '@vant/weapp/notify/notify';
Component({
  behaviors:[storeBindingsBehavior] ,
  storeBindings:{
    store,
    fields:{
      question:()=>store.question,
    },
    actions:{
      updateQues:'updateQues'
    }
  },
  /**
   * 组件的属性列表
   */
  properties: {
    
  },

  options:{
    "styleIsolation": "apply-shared"
  },

  /**
   * 组件的初始数据
   */
  data: {},

  /**
   * 组件的方法列表
   */
  methods: {
    feedback: async function (params) {
      //这里要拿到题号和当前练习章节
      let selectLib = app.globalData.selectLib
      let question = this.data.question
      console.log(question)
      let res1 = await wx.cloud.database().collection("feedBack").where({
        selectLib: selectLib,
        question: question,
        updated:false
      }).get()
      if (res1.data.length > 0) { //如果有人已经反馈过了，就不用反馈了
        Notify({
          message:"有人反馈过了",
          context:this,
          background: '#ffe1e1',
        })
      } else {
        let account = await wx.getStorageSync('user').account
        let response = await wx.cloud.database().collection("feedBack").add({
          data: {
            account: account,
            selectLib: selectLib,
            question: question,
            time: Date.now(),
            updated:false
          }
        }).then()
        if (response.errMsg == "collection.add:ok") {
          Notify({
            message:"谢谢您的反馈",
            context:this,
            background: '#FFFFCC',
          })
        }
      }
    }
  }
})